import { BuildingTreeVO, BuildingTreeQuery } from '@/api/dormitory/buildingTree/types';
import { listBuildingTree } from '@/api/dormitory/buildingTree';
import { handleTree } from '@/utils/ruoyi';
import { useDictStore } from '@/store/modules/dict';

const queryParamsTree = reactive<BuildingTreeQuery>({
  parentId: undefined,
  type: undefined,
  name: undefined,
  orderNum: undefined,
  status: 1
});
/**
 * 获取字典数据
 */
export const useDormitoryTree = (...args: string[]) => {
  const res = ref<{
    [key: string]: BuildingTreeVO[];
  }>({});
  // const args = ['buildingTreeList'];
  return (() => {
    args.forEach(async (dictType) => {
      res.value[dictType] = [];
      const dicts = useDictStore().getDict(dictType);
      if (dicts) {
        res.value[dictType] = dicts;
      } else {
        await listBuildingTree(queryParamsTree).then((respon) => {
          const data = handleTree<BuildingTreeVO>(respon.data, 'id', 'parentId');
          console.log(data), 555;
          res.value[dictType] = data;
        });
      }
    });
    return res.value;
  })();
};
